var sizeHeight = false;
var resizetimer = null;

$(window).resize(setCalSize);
$(document).ready(setCalSize);

function setCalSize() {
	if (resizetimer) clearTimeout(resizetimer);
	resizetimer = setTimeout(setCalSizeNow, 200);
}

function setCalSizeNow() {
	var h = 0;
	var cals = $(".calendarArea");
	cals.each(function(i) { $(this).css({ position: "absolute", "z-index": "20000000" }); });
	cals.each(function(i) {
		var ca = $(this);
		ca.width(ca.parent().width());
		if (sizeHeight) {
			var rows = ca.find(".calDayRow");
			h = ca.parent().innerHeight();
			var headerH = 0;
			ca.find(".calHeaderRow").each(function() { headerH += $(this).outerHeight(); });
			var dayRowH = ((h - headerH) / rows.length) - 1;
			ca.find(".innerDay").each(function(i) { $(this).height(dayRowH); });
		}
		else {
			ca.find(".calDayRow").each(function(i) {
				var w = $(this).children(0).width();
				$(this).find(".innerDay").each(function(i) { $(this).height(w); });
			});
		}
	});
	cals.each(function(i) { $(this).css("position", "static"); });
}
